package com.example.demo.service.serviceImpl;

import com.example.demo.entity.User;
import com.example.demo.mapper.UserMapper;
import com.example.demo.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 用户基本信息表(User)Service层
 *
 * @author makejava
 * @since 2021-02-23 17:48:33
 */
@Service
@Transactional(rollbackFor = {RuntimeException.class, Exception.class})
public class UserServiceImpl implements UserService  {
        @Autowired
        private UserMapper userMapper;


 /**
     * 通过ID和其他条件查询单条数据
     *
     * @param user 实例对象
     * @return 实例对象
     */
       @Override
 @Transactional(rollbackFor = {RuntimeException.class, Exception.class})
     public User queryUserLimit1(User user){
     return  userMapper.queryUserLimit1( user);
     }
     
 /**
     * 查询指定行数据
     * @param user 实例对象
     * @param offset 查询起始位置
     * @param limit 查询条数
     * @return 对象列表
     */
       @Override
 @Transactional(rollbackFor = {RuntimeException.class, Exception.class})
  public   List<User> queryAllUserByLimit( User user, Integer offset,  Integer limit){
   return userMapper.queryAllUserByLimit(user, offset,limit);
  }

  /**
     * 查询数据条数
     * @return 条数
     */
       @Override
 @Transactional(rollbackFor = {RuntimeException.class, Exception.class})
   public int countAllUser(User user){
   return userMapper.countAllUser( user);
   }
   /**
     * 通过实体作为筛选条件查询
     *
     * @param user 实例对象
     * @return 对象列表
     */
       @Override
 @Transactional(rollbackFor = {RuntimeException.class, Exception.class})
   public List<User> queryAllUser(User user){
   return userMapper.queryAllUser(user);
   }
  /**
     * 新增数据
     *
     * @param user 实例对象
     * @return 影响行数
     */
     @Override
   @Transactional(rollbackFor = {RuntimeException.class, Exception.class})
    public int insertUser(User user){
    return  userMapper.insertUser( user);
    }
  /**
     * 修改数据
     *
     * @param user 实例对象
     * @return 影响行数
     */
       @Override
 @Transactional(rollbackFor = {RuntimeException.class, Exception.class})
     public  int updateUser(User user){
         return userMapper.updateUser( user);
     }

    /**
     * 通过主键删除数据
     * @param userId 主键
     * @return 影响行数
     */
      @Override
  @Transactional(rollbackFor = {RuntimeException.class, Exception.class})
   public  int deleteUserById(String userId){
   return  userMapper.deleteUserById( userId);
   }
     /**
     * 通过主键列表删除，列表长度不能为0
     * @param list 集合
     * @return 条数
     */
      @Override
  @Transactional(rollbackFor = {RuntimeException.class, Exception.class})
  public  int deleteUserByIds( List<String> list){
    return  userMapper.deleteUserByIds(  list);
  }
    
       /**
     * 通过主键修改实体列表，列表长度不能为0，注意：当实体属性为null时，对应的列也会别更新为null
     * @param list 集合
     * @return 条数
     */
       @Override
 @Transactional(rollbackFor = {RuntimeException.class, Exception.class})
   public int updateUserBatch( List<User> list){
   return  userMapper.updateUserBatch(list);
   }
    /**
     * 批量其他列,除主键以外的列，列表长度不能为0,字段是空的就置为null
     * @param list 集合
     * @return 条数
     */
      @Override
  @Transactional(rollbackFor = {RuntimeException.class, Exception.class})
 public   int insertUserBatch( List<User> list){
 return userMapper.insertUserBatch( list);
 }
      /**
     * 通过实体非空属性删除
     * @param user  实体
     * @return 条数
     */
        @Override
@Transactional(rollbackFor = {RuntimeException.class, Exception.class})
  public   int deleteUserByEntity( User user){
  return  userMapper.deleteUserByEntity(  user);
  }
    /**
     * 通过实体不为空的属性作为筛选条件查询列表
     * @param user  实体
     * @return list
     */
       @Override
 @Transactional(rollbackFor = {RuntimeException.class, Exception.class})
   public  List<User> listUserByEntity(User user){
   return userMapper.listUserByEntity( user);
   }

 /**
     * 新增实体属性不为null的列
     * @param user  实体
     * @return 条数
     */
       @Override
 @Transactional(rollbackFor = {RuntimeException.class, Exception.class})
   public  int insertUserSelect( User user){
      return userMapper.insertUserSelect( user);

   }
   
      /**
     * 批量新增新增实体属性不为null的列
     * @param list  实体
     * @return 条数
     */
        @Override
@Transactional(rollbackFor = {RuntimeException.class, Exception.class})
  public  int insertUserListSelect( List<User> list){

     return userMapper.insertUserListSelect( list);
      }
     /**
     * 通过实体不为空的属性作为筛选条件查询单个
     * @param user  实体
     * @return 单个
     */
     @Override
   @Transactional(rollbackFor = {RuntimeException.class, Exception.class})
    public  User getUserByEntity(User user){
     return  userMapper.getUserByEntity(user);
    }

}

